package cn.bby.tools.dialog.common;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.ValidationInfo;
import com.intellij.openapi.wm.IdeFocusManager;
import org.jetbrains.annotations.Nullable;

/**
 * @description: BaseValidationDialog
 * @author: bby
 * @date: 2025/11/4 16:58
 * @version: 1.0
 */
public abstract class BaseValidationDialog extends DialogWrapper {
    protected Project project;
    public BaseValidationDialog(@Nullable Project project) {
        super(project);
        this.project = project;
    }

    protected BaseValidationDialog(@Nullable Project project, boolean canBeParent) {
        super(project, canBeParent);
    }

    /**
     * 验证
     * @return 是否验证不通过
     */
    public boolean isValidError() {
        ValidationInfo validationInfo = doValidate();
        if (validationInfo != null) {
            if (validationInfo.component != null && validationInfo.component.isVisible()) {
                IdeFocusManager.getInstance(null).requestFocus(validationInfo.component, true);
            }
            return true;
        }
        return false;
    }
}
